//package me.firstapp.manage.common;
//
//import java.io.BufferedReader;
//import java.io.File;
//import java.io.FileReader;
//import java.io.IOException;
//import java.util.UUID;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.RequestPart;
//import org.springframework.web.multipart.MultipartFile;
//
//import me.firstapp.common.exception.ServiceException;
//import me.firstapp.common.exception.StatusHouse;
//import me.firstapp.common.json.SingleObject;
//import me.firstapp.common.utils.FileUtils;
//import me.firstapp.common.utils.ResponseUtils;
//import me.firstapp.common.utils.StrUtils;
//import me.firstapp.module.weixin.kami.KaMi;
//import me.firstapp.service.weixin.kami.KaMiService;
//
//@Controller
//@RequestMapping(value = "/upload")
//public class UploadAct extends BaseManage {
//
//	private static Logger logger = LoggerFactory.getLogger(UploadAct.class);
//
//	@Autowired
//	private KaMiService kaMiService;
//
//	@RequestMapping(value = "/importKamiFile.do", method = RequestMethod.POST)
//	public void importKamiFile(@RequestPart(value = "kamiFile") MultipartFile kamiFile, Long kaMiProductId,
//			HttpServletRequest request, HttpServletResponse response) {
//		SingleObject<Object> result = new SingleObject<Object>();
//
//		try {
////			File newFile = new File("D:/kamifile/" + UUID.randomUUID().toString().replace("-", "") + ".txt");
//			File newFile = new File("/mnt/kamifile/" + UUID.randomUUID().toString().replace("-", "") + ".txt");
//			FileUtils.inputstreamtofile(kamiFile.getInputStream(), newFile);
//			BufferedReader reader = null;
//			try {
//				System.out.println("以行为单位读取文件内容，一次读一整行：");
//				reader = new BufferedReader(new FileReader(newFile));
//				String tempString = null;
//				int line = 1;
//				// 一次读入一行，直到读入null为文件结束
//				while ((tempString = reader.readLine()) != null) {
//					// 显示行号
//					System.out.println("line " + line + ": " + tempString);
//					saveKami(kaMiProductId, tempString);
//					logger.info("已写入第" + line + "个卡密到数据库");
//					line++;
//				}
//				reader.close();
//				newFile.delete();
//			} catch (IOException e) {
//				e.printStackTrace();
//				throw e;
//			} finally {
//				if (reader != null) {
//					try {
//						reader.close();
//					} catch (IOException e1) {
//						e1.printStackTrace();
//						throw e1;
//					}
//				}
//			}
//			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
//		} catch (IOException e) {
//			e.printStackTrace();
//			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
//			logger.error("导入失败", e);
//		} catch (ServiceException e) {
//			e.printStackTrace();
//			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
//			logger.error("导入失败", e);
//		} catch (Exception e) {
//			e.printStackTrace();
//			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
//			logger.error("导入失败", e);
//		}
//		ResponseUtils.renderJson(response, result);
//	}
//
//	private void saveKami(Long kaMiProductId, String line) {
//		if (StrUtils.isNULL(line)) {
//			return;
//		}
//		String[] arra = line.split("-");
//		String account = arra[0];
//		String key = arra[1];
//		KaMi kami = kaMiService.findByAccountAndKey(kaMiProductId, account, key);
//		if (null == kami) {
//			kaMiService.executeAddKaMi(kaMiProductId, account, key, KaMi.GIVE_TYPE_CAN_NOT);
//		}
//	}
//}
